<?php
class lienhe
{
	var $Yahoo;
	var $TenNguoiLienHe;

  
  function Convert($arr)
  {
	  $obj=new lienhe();
	  $obj->Yahoo=$arr['Yahoo'];
	  $obj->TenNguoiLienHe=$arr['TenNguoiLienHe'];
	  return $obj;
  }
  //Lấy tất cả liên hệ
  static function GetAll($page = 1, $pagesize = 9)
  {
	  $start = ($page-1)*$pagesize;
	  $arr= array();
	  $str= "SELECT * FROM lienhe limit $start,$pagesize" ;
	  $kq=Query($str);
	  $i=0;
	  while($row=mysql_fetch_array($kq))
	  {
		  $arr[$i]=self::ConVert($row);
		  $i++;	
	  }	
	  return $arr;
  }
  //Hàm đếm số lượng liên hệ
	static function CountLienHe()
	{
		$str = "select count(Yahoo) from lienhe";
		$kq = Query($str);
		$row = mysql_fetch_array($kq);
		return $row[0];
	}
  
  //Hàm thêm liên hệ
  static function ThemLienHe($yahoo,$ten)
  {
	  $str=	"INSERT INTO lienhe(Yahoo,TenNguoiLienHe)
	  			  VALUES('".$yahoo."','".$ten."')";				 
	  return Query($str);	
  }
  
  //Hàm sửa liên hệ
	static function SuaLienHe($yahoo,$ten,$dk)
  {
	  $str=	"UPDATE lienhe 
	  			  SET Yahoo = '".$yahoo."',
				  		TenNguoiLienHe = '".$ten."'
				  WHERE Yahoo='".$dk."'";
	  return Query($str);	
  }
  
  //Hàm xóa tài khoản
	static function Xoa($yahoo)
	{
		$str="DELETE FROM lienhe WHERE Yahoo='".$yahoo."'";	
		return Query($str);
	}
	
	 //Hàm tìm kiếm theo Tên
  static function TimTheoTen($ten)
  {
	  $arr= array();
	  $str= "SELECT * FROM lienhe WHERE  TenNguoiLienHe like '%$ten%'" ;
	  $kq=Query($str);
	  $i=0;
	  while($row=mysql_fetch_array($kq))
	  {
		  $arr[$i]=self::ConVert($row);
		  $i++;	
	  }	
	  return $arr;
  }
  
  //Hàm tìm kiếm theo Yahoo
  static function TimTheoYahoo($yahoo)
  {
	  $arr= array();
	  $str= "SELECT * FROM lienhe WHERE  Yahoo like '%$yahoo%'" ;
	  $kq=Query($str);
	  $i=0;
	  while($row=mysql_fetch_array($kq))
	  {
		  $arr[$i]=self::ConVert($row);
		  $i++;	
	  }	
	  return $arr;
  }
  
   //Hàm lấy liên hệ theo id
  static function GetByID($id)
  {
	  $arr= array();
	  $str= "SELECT * FROM lienhe WHERE  Yahoo = '".$id."'" ;
	  $kq=Query($str);
	  $i=0;
	  while($row=mysql_fetch_array($kq))
	  {
		  $arr[$i]=self::ConVert($row);
		  $i++;	
	  }	
	  return $arr;
  }
}
?>